<template>
	<view>
		<uni-section title="请行选择学期" type="line"></uni-section>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					当前选择
				</view>
				<view class="uni-list-cell-db">
					<picker v-if="semList.length > 0" @change="changeSemster" :value="semIndex" :range="semList" range-key="title">
						<view class="uni-input">{{ semList[semIndex].title }}</view>
					</picker>
				</view>
			</view>
		</view>
		<view class="uni-title uni-common-pl">班级</view>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					当前选择
				</view>
				<view class="uni-list-cell-db">
					<picker v-if="classList.length > 0" @change="changeClass" :value="classIndex" :range="classList" range-key="title">
						<view class="uni-input">{{ classList[classIndex].title }}</view>
					</picker>
				</view>
			</view>
		</view>
		<uni-list>
			<uni-list-item :title="t.dates" :rightText="t.className" :note="t.stuName + ' ' + t.ruleName" v-for="t in list"/>
		</uni-list>
		<uni-load-more :status="more" @clickLoadMore="getList"></uni-load-more>
	</view>
</template>

<script>
	import { listSemster, listClass } from '@/api/base.js'
	import { listStudent } from '@/api/quantify.js'
	export default {
		data() {
			return {
				semList: [],
				classList: [],
				semIndex:0,
				classIndex: 0,
				semId: null,
				classId: null,
				list: [],
				param:{
					pageNum: 0,
					pageSize: 10,
					orderByColumn: 't.id',
					isAsc: 'DESC'
				},
				more: 'noMore',
				loaded: 0,
			}
		},
		onLoad(option) {
			listSemster({status: '1'}).then(response => {
				for(var i=0;i<response.rows.length;i++){
					if(response.rows[i]['isCurrent'] == 'Y'){
						this.semId = response.rows[i]['id'];
						this.semIndex = i;
						break;
					}
				}
				this.semList = response.rows;
				this.getList();
			})
			listClass({status: '1'}).then(response => {
				this.classList = response.rows;
				this.classId = response.rows[0]['id'];
				this.getList();
			})
		},
		methods:{
			getList() {
				let q = this.param;
				if(this.semId) q.semId = this.semId;
				if(this.classId) q.classId = this.classId;

				if(this.loaded == 0){
					this.param.pageNumber = 1;
				}
				this.more = 'loading';

				listStudent(q).then(response => {
					this.list = response.rows;

					this.loaded += response.rows.length;
					if(this.total > this.loaded){
						this.more = 'more';
					}else{
						this.more = 'noMore';
					}
				});
			},
			changeClass(e) {
				this.classIndex = e.target.value;
				this.classId = this.classList[this.classIndex]['id'];
				this.getList();
			},
			changeSemster(e) {
				this.semIndex = e.target.value;
				this.semId = this.semList[this.semIndex]['id'];
				this.getList();
			}
		}
	}
</script>

<style>
</style>
